<?php

namespace app\crm\model;

use app\admin\model\Common;
use app\mini\model\SendUrlModel;
//use think\model\concern\SoftDelete;


class ShortMessageTplModel extends Common
{
//    use SoftDelete;

    protected $name = 'short_message_tpl';



    protected $createTime = 'created_at';

    protected $updateTime = 'updated_at';

    protected $deleteTime = 'deleted_at';

    protected $autoWriteTimestamp = true;

    public function shortMessageMass($tel,$tplId,$user_id)
    {
//        $tplId = $data['tpl_id']??0;
        $tel = $tel??[];
        $sendUrlModel = new SendUrlModel();
        $url = "https://sms.yunpian.com/v2/sms/tpl_batch_send.json";
        $tel=implode(',',$tel);
        $params = [
            'apikey' => '9616eb7d8bd7ff79ca24af3fad8f192b',
            'mobile' => $tel,
            'tpl_id' => $tplId,
            'tpl_value' =>""
        ];
        if(!empty($res['code']))
        {
            return $this->failed($res['code'],$res['detail']);
        }
        $res = $sendUrlModel->send_mass_url($url,$params);
        $res = json_decode($res,true);
        ShortMessageFast::create([
            'user_id'=>$user_id,
            'tpl_id'=>$tplId,
            'fast'=>$res['total_fee'],
            'time'=>time()
        ]);
        return $res;
    }

}
